package com.qys.livesMall.finance.service.impl;

import com.qys.livesMall.finance.dao.FinanceAccountDetailDao;
import com.qys.livesMall.finance.mapper.FinanceAccountDetailMapper;
import com.qys.livesMall.finance.model.dto.AccountDetailSearch;
import com.qys.livesMall.finance.model.dto.AccountHandle;
import com.qys.livesMall.finance.model.entity.FinanceAccount;
import com.qys.livesMall.finance.model.entity.FinanceAccountDetail;
import com.qys.livesMall.finance.service.FinanceAccountDetailService;
import com.qys.livesMall.framework.view.Paging;
import com.qys.livesMall.framework.view.QysPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

/**
 * <p>
 * 店铺余额明细 服务实现类
 * </p>
 *
 * @author
 * @since 2023-06-06
 */
@Service
public class FinanceAccountDetailServiceImpl implements FinanceAccountDetailService {

    @Autowired
    private FinanceAccountDetailDao accountDetailDao;

    @Autowired
    private FinanceAccountDetailMapper accountDetailMapper;


    @Override
    public void add(AccountHandle handle, FinanceAccount account) {
        FinanceAccountDetail detail=new FinanceAccountDetail();
        detail.setBalanceId(account.getId());
        detail.setBusinessNo(handle.getBusinessNo());
        detail.setPayMethod(handle.getPayMethod());
        detail.setType(handle.getTradeTypeEnum().getType());
        detail.setInOut(handle.getTradeTypeEnum().getInOut());
        detail.setCategory(handle.getBusinessType().getType());
        detail.setCode(handle.getBusinessType().getCode());
        detail.setAmountIncurred(handle.getAmountIncurred());
        detail.setDescription(handle.getDescription());
        detail.setPayAfter(account.getBalance().toString());
        detail.setPayDate(LocalDateTime.now());
        detail.setSerialNumber(handle.getSerialNumber());
        detail.setExpectedAmount(handle.getAmountIncurred());
        accountDetailDao.save(detail);
    }

    @Override
    public QysPage<FinanceAccountDetail> list(AccountDetailSearch search) {
        Paging<FinanceAccountDetail> page=accountDetailMapper.search(new Paging<>(search));
        return QysPage.to(page);
    }
}
